package com.ruoyi.tws.controller;

import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.tws.api.domain.Order;
import com.ruoyi.tws.domain.vo.LocationVO;
import com.ruoyi.tws.service.IOrderService;
import com.ruoyi.tws.third.OpenApiService;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;

@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/gis")
public class GisController extends BaseController {

    @Autowired
    OpenApiService openApiService;

    @Autowired
    private IOrderService iOrderService;

    /***
     * 实时位置
     * @param orderId
     * @return
     */
    @GetMapping("/getSingleLocation/{orderId}")
    public LocationVO getSingleLocation(@PathVariable("orderId") Long orderId) {
        Order order = iOrderService.getById(orderId);
        return openApiService.vLastLocationV3(order.getVehicleNumber());
    }

    /** 车辆订阅离线提醒 */
    @GetMapping("/subscribe/{ids}")
    public AjaxResult subscribe(@PathVariable Long[] ids) {
        return toAjax(openApiService.vnoOutReg(Arrays.asList(ids)));
    }

    /** 删除车辆订阅离线提醒 */
    @GetMapping("/delSubscribe/{ids}")
    public AjaxResult delSubscribe(@PathVariable Long[] ids) {
        return toAjax(openApiService.vnoOutDel(Arrays.asList(ids)));
    }

}
